home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / DATABASE / OBJ1_2.ZIP;1 / C_FRAME.PRG < prev    next >
Encoding:
Text File  |  1993-01-21  |  5.7 KB  |  181 lines

  1. //*****************************************************************************
  2. // C_Frame.prg
  3. // Frame class for OBJECT v2.03
  4. // Copyright (c) 1991, JHK, JHK-Software, Piestany
  5. // Compile with: /N/M/W/A
  6. //-----------------------------------------------------------------------------
  7.  
  8. #include "Box.ch"
  9. #include "InKey.ch"
  10. #include "Object.ch"
  11.                                   //use for move & size frame
  12. create class Frame from Loc       //Magic sequence: Init,  Paint,Hide... Done
  13.   export:                         //            or: Init, Drag, Done
  14.   var RowSize  // MaxRow()-7
  15.   var ColSize  // MaxCol()-9
  16.   var MaxRows  // MaxRow()-3                            //maximum available RowSize
  17.   var MaxCols  // MaxCol()-1                            //maximum available ColSize
  18.   var MinRows  // 1                                     //minimum available RowSize
  19.   var MinCols  // 5                                     //minimum available ColSize
  20.   var Screen   // ""
  21.   var Color    // ListAsArray(m->Color:Edit)[nEnhanced]
  22.   var Visible  // false
  23.   method New=FrameNew         //o:New()
  24.   method Init=FrameInit            //o:Init(R,C,Rs,Cs,Clr)
  25.   method Paint=FramePaint          //o:Paint()
  26.   method Hide=FrameHide            //o:Hide()
  27.   method Move=FrameMove            //o:Move(dR,dC)
  28.   method Size=FrameSize            //o:Size(dR,dC)
  29.   method Drag=FrameDrag            //o:Drag(lCanSize)
  30.   method Done=FrameDone            //o:Done()
  31.   endclass
  32.  
  33.  
  34. //*****************************************************************************
  35. // Frame:New() --> self
  36. // initialize new object
  37. //
  38. constructor FrameNew()
  39.   ::RowSize:= MaxRow()-7
  40.   ::ColSize:= MaxCol()-9
  41.   ::MaxRows:= MaxRow()-3
  42.   ::MaxCols:= MaxCol()-1
  43.   ::MinRows:= 1
  44.   ::MinCols:= 5
  45.   ::Screen:= ""
  46.   ::Color:= ListAsArray(m->Color:Edit)[nEnhanced]
  47.   ::Visible:= false
  48.   return(self)
  49.  
  50.  
  51. //*****************************************************************************
  52. // Frame:Init(R,C,Rs,Cs,Clr,Shadow) --> true
  53. // initialize new frame, write it into screen.
  54. //
  55. method function FrameInit(R,C,Rs,Cs,Clr)
  56.   ::super(Loc):Init(R,C)
  57.   store value Rs into ::RowSize
  58.   store value Cs into ::ColSize
  59.   store value Clr into ::Color
  60.   return(true)
  61.  
  62.  
  63. //*****************************************************************************
  64. // Frame:Paint() --> true
  65. // paint frame.
  66. //
  67. method function FramePaint()
  68.   local R,C,R2,C2,Scr
  69.   if !::Visible
  70.     R:=::Row
  71.     C:=::Col
  72.     R2:=R+::RowSize+1
  73.     C2:=C+::ColSize+1
  74.     ::Screen:=SaveScreen(R,C,R2,C2)
  75.     @ R,C,R2,C2 box "∞∞∞∞∞∞∞∞" color ::Color
  76.     ::Visible:=true
  77.   endif
  78.   return(true)
  79.  
  80.  
  81. //*****************************************************************************
  82. // Frame:Hide() --> true
  83. // hide the frame.
  84. //
  85. method function FrameHide()
  86.   local R,C,R2,C2
  87.   if ::Visible
  88.     R:=::Row
  89.     C:=::Col
  90.     R2:=R+::RowSize+1
  91.     C2:=C+::ColSize+1
  92.     RestScreen(R,C,R2,C2,::Screen)            //restore background
  93.     ::Visible:=false
  94.   endif
  95.   return(true)
  96.  
  97.  
  98. //*****************************************************************************
  99. // Frame:Move(dR,dC)  --> true
  100. // move the frame into new location (and make it visible).
  101. //
  102. method function FrameMove(dR,dC)
  103.   if ::Row+dR<1; dR:=1-::Row; endif
  104.   if ::Col+dC<0; dC:=-::Col; endif
  105.   if ::Row+::RowSize+1+dR>=MaxRow(); dR:=MaxRow()-::Row-::RowSize-2; endif
  106.   if ::Col+::ColSize+1+dC>MaxCol();  dC:=MaxCol()-::Col-::ColSize-1; endif
  107.   DispBegin()
  108.     ::Hide()
  109.     ::Row+=dR
  110.     ::Col+=dC
  111.     ::Paint()
  112.   DispEnd()
  113.   return(true)
  114.  
  115.  
  116. //*****************************************************************************
  117. // Frame:Size(dR,dC) --> true
  118. // resize the frame.
  119. //
  120. method function FrameSize(dR,dC)
  121.   if ::RowSize+dR<::MinRows; dR:=::MinRows-::RowSize; endif
  122.   if ::ColSize+dC<::MinCols; dC:=::MinCols-::ColSize; endif
  123.   if ::RowSize+dR>::MaxRows; dR:=::MaxRows-::RowSize; endif
  124.   if ::ColSize+dC>::MaxCols; dC:=::MaxCols-::ColSize; endif
  125.   if ::Row+::RowSize+1+dR>=MaxRow(); dR:=MaxRow()-::Row-::RowSize-2; endif
  126.   if ::Col+::ColSize+1+dC>MaxCol(); dC:=MaxCol()-::Col-::ColSize-1; endif
  127.   DispBegin()
  128.     ::Hide()
  129.     ::RowSize+=dR
  130.     ::ColSize+=dC
  131.     ::Paint()
  132.   DispEnd()
  133.   return(true)
  134.  
  135.  
  136. //*****************************************************************************
  137. // Frame:Drag(lCanSize) --> lDragget
  138. // user move&resize this frame.
  139. //
  140. method function FrameDrag(lCanSize,RowMin,ColMin)
  141.   local Ch
  142.   local lDragget:=false  //assume
  143.   default lCanSize to true
  144.   default RowMin to 1
  145.   default ColMin to 5
  146.   if !::Visible; ::Paint(); endif
  147.   SaveDOut(ResTxt(155))
  148.   SaveHelpIdx({13})
  149.   repeat
  150.     DisableHelp()
  151.     Ch:=PauseKey(0)
  152.     EnableHelp()
  153.     do case
  154.       case Ch==K_UP;     lDragget:=true; ::Move(-1,0)
  155.       case Ch==K_DOWN;   lDragget:=true; ::Move(1,0)
  156.       case Ch==K_LEFT;   lDragget:=true; ::Move(0,-1)
  157.       case Ch==K_RIGHT;  lDragget:=true; ::Move(0,1)
  158.       case Ch==Asc("8"); if lCanSize and ::RowSize>::MinRows; lDragget:=true; ::Size(-1,0); endif
  159.       case Ch==Asc("2"); if lCanSize and ::RowSize<::MaxRows; lDragget:=true; ::Size(1,0); endif
  160.       case Ch==Asc("4"); if lCanSize and ::ColSize>::MinCols; lDragget:=true; ::Size(0,-1); endif
  161.       case Ch==Asc("6"); if lCanSize and ::ColSize<::MaxCols; lDragget:=true; ::Size(0,1); endif
  162.       otherwise;         Ch:=nSwapTask
  163.     endcase
  164.   until Ch==nSwapTask
  165.   RestHelpIdx()
  166.   ::Hide()
  167.   RestDOut()
  168.   return(lDragget)
  169.  
  170.  
  171. //*****************************************************************************
  172. // Frame:Done()  --> true
  173. // destroy this frame.
  174. //
  175. method function FrameDone()
  176.   ::Hide()
  177.   return(true)
  178.  
  179. //------------------------------------------------------- eof (c)JHK ----------
  180.  
  181.